//
//  ST_TianDailyTaskBannerSectionReusableView.swift
//  btvideo
//
//  Created by Jason on 2021/11/3.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import Foundation
import UIKit

class ST_TianDailyTaskBannerSectionReusableView: UICollectionReusableView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(bannerImageView)
        bannerImageView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(ScreenWidth/375.0*80)
        }
        
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.top.equalTo(bannerImageView.snp.bottom).offset(15)
            make.height.equalTo(20)
        }
        
        self.backgroundColor = .white
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var titleLabel:UILabel = {
        let l = UILabel()
        l.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
        l.font = .systemFont(ofSize: 14, weight: .regular)
        return l
    }()
    
    fileprivate lazy var bannerImageView:UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        v.clipsToBounds = true
        v.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(push_challenge_controller))
        v.addGestureRecognizer(tap)
        //v.cornerRadius = 5
        return v
    }()
    
    func bind(title:String,banner:String) {
        
        titleLabel.text = title
        
        bannerImageView.pin_setImage(from: banner.url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
    }
}

extension ST_TianDailyTaskBannerSectionReusableView{
    
    @objc fileprivate func push_challenge_controller(){
        
        ST_BTUserInfoManager.shared.judge_account_frozen().withUnretained(self).subscribe(onNext: { own,_ in
            
                own.parentViewController?.navigationController?.pushViewController(ST_TianChallengeController(), animated: true)
            
        }).disposed(by: rx.disposeBag)
        
        
    }
}

